//
//  RegistVerifyController.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/13.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "RegistVerifyController.h"
#import "RegistVerifyView.h"
#import "UserDataCenter.h"
#import "RegistUserInfoController.h"

@interface RegistVerifyController ()<RegsitVerifyViewDelegate>

@property (nonatomic, strong) RegistVerifyView *verifyView;
@property (nonatomic, strong) UserDataCenter *dataCenter;

@end

@implementation RegistVerifyController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.baseTitle = @"验证手机号";
    self.rightBtnTitle = @"返回";
    
    _dataCenter = [UserDataCenter new];
    
    [self makeRegistVerifyView];
}

- (void)makeRegistVerifyView
{
    _verifyView = [RegistVerifyView new];
    _verifyView.delegate = self;
    [self.baseView addSubview:_verifyView];
    [_verifyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.mas_equalTo(0);
    }];
}

- (void)clickSendVerifyWithPhone:(NSString *)phone
{
    if ([NSString isEmptyString:phone] == YES || [NSString checkIsPhone:phone] == NO) {
        [YJProgressHud showErrorHud:@"请输入有效手机号"];
    }else{
        [_verifyView startTime];
        [_dataCenter sendVerifyWithPhone:phone complation:^(id data) {
            if (data == nil) {
                [YJProgressHud showSuccessHud:@"短信已发送"];
            }else{
                [_verifyView recoverTime];
                [YJProgressHud showErrorHud:data];
            }
        }];
    }
}

- (void)clickNextStepWithPhone:(NSString *)phone verifyCode:(NSString *)code
{

    if ([NSString isEmptyString:code] == YES || code.length != 6) {
        [YJProgressHud showErrorHud:@"请输入6位验证码"];
    }else{
        [YJProgressHud showLoadingHud:@"验证中..."];
        [_dataCenter verifyCodeWithPhone:phone code:code complation:^(id data) {
            if (data == nil) {
                [YJProgressHud dissmiss];
                RegistUserInfoController *registInfoController = [[RegistUserInfoController alloc]init];
                registInfoController.phone = phone;
                [self.navigationController pushViewController:registInfoController animated:YES];
            }else{
                [YJProgressHud showErrorHud:data];
            }
        }];
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
